#include <bits/stdc++.h>

using namespace std;

const int MAXN = 4e5+10;
const int mod = 10007;

struct bignum{
	int arr[MAXN],len;
	bignum(int x = 0):len(x){memset(arr,0,sizeof(arr));}
	int & operator [](int x){return arr[x];} const int operator [](int x)const{return arr[x];}
	void read(){len=0;char ch=getchar();for(;!isdigit(ch);ch=getchar());for(;isdigit(ch);ch=getchar()) arr[++len]=ch^48;reverse(arr+1,arr+len+1);}
	void limit(){for(int i = 1;i <= len;i++) if(arr[i] > 9) arr[i+1]+=arr[i]/10,arr[i]%=10;while(arr[len+1]){len++;if(arr[len]>9)arr[len+1] += arr[len]/10,arr[len]-=arr[len]/10*10;}while(arr[len]==0&&len>1) len--;}
	friend int operator % (bignum a,int x){int ans = 0;for(int i = a.len;i >= 1;i--)ans = (ans * 10 + a[i])% mod;return ans%x;}
}nn;

int main (){
	nn.read(); int n = nn % mod;
	long long ans = 1ll * n * (n+1) % mod * (n+2) % mod;ans = ans * 5004 % mod * 3336 % mod;
	printf("%lld\n",ans);return 0;
}
